﻿using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace BLL.Model
{
    public class Profile
    {
        public Profile()
        {
            RegexPatterns = new List<ProgramAccessItem>();
        }

        public bool UseEncryption { get; set; }
        public bool DoNotUseAutoLogin { get; set; }

        public bool ProgramAclEnabled { get; set; }
        public bool UseWhiteList { get; set; }
        public List<ProgramAccessItem> RegexPatterns { get; set; }

        public bool IsAllowed(string programName)
        {
            if (!ProgramAclEnabled)
                return true;

            // Return true if a rule matches if we use white list, and return false if we use blacklist
            var matchRet = UseWhiteList;

            foreach (var rule in RegexPatterns)
            {
                if (rule.IsEnabled)
                {
                    var r = new Regex(rule.RegexPattern, RegexOptions.IgnoreCase);
                    if (r.IsMatch(programName))
                        return matchRet;
                }
            }
            return !matchRet;
        }
    }
}